﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DalGen.Util;
using DalGen.ConnForm;
using DalGen.Entity;

namespace DalGen
{
    public partial class ManageForm : Form
    {
        public ManageForm()
        {
            InitializeComponent();
            
        }

        private void ManageForm_Load(object sender, EventArgs e)
        {
            BindData();
        }

        private void BindData()
        {
            object ProjectInfo = XmlHelper.GetProjectList();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = ProjectInfo;

        }
        private void btnAdd_Click(object sender, EventArgs e)
        {

           
            DBSourceForm form = new DBSourceForm();
            form.Show();
            this.Hide();
        }


        private string GetGuid()
        {
            string guid = "";
            if (this.dataGridView1.SelectedRows.Count == 0)
            {
                MessageBox.Show("请先选中行!");

            }
            else
            {
                guid = this.dataGridView1.SelectedRows[0].Cells["GUID"].Value.ToString();
               
            }
            return guid;
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
           
            XmlHelper.Remove(GetGuid());

            BindData();
        }

        private void btnconn_Click(object sender, EventArgs e)
        {
            string guid = GetGuid();

            EProjectInfo entity = XmlHelper.GetEntity(guid);

            MainForm from = new MainForm();
            from.Show();
            this.Hide();

        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnconn_Click(sender, null);
        }

        private void ManageForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit(); 
        }
    }
}
